package com.phantasy.scene.tile.gameAstar
{
	public class BinaryHeap
	{
		public var a:Array;
		public var justMinFun:Function;
		
		public function BinaryHeap(_arg1:Function=null)
		{
			this.a = [];
			this.justMinFun = function (_arg1:Object, _arg2:Object):Boolean
			{
				return ((_arg1 < _arg2));
			};
			super();
			this.a.push(-1);
			if (_arg1 != null)
			{
				this.justMinFun = _arg1;
			};
		}
		
		public function ins(_arg1:Object):void
		{
			var _local4:Object;
			var _local2:int = this.a.length;
			this.a[_local2] = _arg1;
			var _local3 = (_local2 >> 1);
			while ((((_local2 > 1)) && (this.justMinFun(this.a[_local2], this.a[_local3]))))
			{
				_local4 = this.a[_local2];
				this.a[_local2] = this.a[_local3];
				this.a[_local3] = _local4;
				_local2 = _local3;
				_local3 = (_local2 >> 1);
			};
		}
		
		public function pop():Object
		{
			var _local6:int;
			var _local7:Object;
			var _local1:Object = this.a[1];
			this.a[1] = this.a[(this.a.length - 1)];
			this.a.pop();
			var _local2:int = 1;
			var _local3:int = this.a.length;
			var _local4 = (_local2 << 1);
			var _local5:int = (_local4 + 1);
			while (_local4 < _local3)
			{
				if (_local5 < _local3)
				{
					_local6 = ((this.justMinFun(this.a[_local5], this.a[_local4])) ? _local5 : _local4);
				}
				else
				{
					_local6 = _local4;
				};
				if (this.justMinFun(this.a[_local6], this.a[_local2]))
				{
					_local7 = this.a[_local2];
					this.a[_local2] = this.a[_local6];
					this.a[_local6] = _local7;
					_local2 = _local6;
					_local4 = (_local2 << 1);
					_local5 = (_local4 + 1);
				}
				else
				{
					break;
				};
			};
			return (_local1);
		}
	}
}